package com.LAPS.dao;

// Generated Dec 4, 2011 6:24:43 PM by Hibernate Tools 3.4.0.CR1

import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Example;

import com.LAPS.Util.HibernateUtil;

/**
 * Home object for domain model class EmployeeWorkschedule.
 * @see com.LAPS.dao.EmployeeWorkschedule
 * @author Hibernate Tools
 */
public class EmployeeWorkscheduleHome {

	private static final Log log = LogFactory
			.getLog(EmployeeWorkscheduleHome.class);

	private final SessionFactory sessionFactory = getSessionFactory();

	protected SessionFactory getSessionFactory() {
		try {
			return HibernateUtil.getSessionFactory();
		} catch (Exception e) {
			log.error("Could not locate SessionFactory in JNDI", e);
			throw new IllegalStateException(
					"Could not locate SessionFactory in JNDI");
		}
	}

	public void persist(EmployeeWorkschedule transientInstance) {
		log.debug("persisting EmployeeWorkschedule instance");
		try {
			sessionFactory.openSession().persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(EmployeeWorkschedule instance) {
		log.debug("attaching dirty EmployeeWorkschedule instance");
		try {
			sessionFactory.openSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(EmployeeWorkschedule instance) {
		log.debug("attaching clean EmployeeWorkschedule instance");
		try {
			sessionFactory.openSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(EmployeeWorkschedule persistentInstance) {
		log.debug("deleting EmployeeWorkschedule instance");
		try {
			sessionFactory.openSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public EmployeeWorkschedule merge(EmployeeWorkschedule detachedInstance) {
		log.debug("merging EmployeeWorkschedule instance");
		try {
			EmployeeWorkschedule result = (EmployeeWorkschedule) sessionFactory
					.openSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public EmployeeWorkschedule findById(com.LAPS.dao.EmployeeWorkscheduleId id) {
		log.debug("getting EmployeeWorkschedule instance with id: " + id);
		try {
			EmployeeWorkschedule instance = (EmployeeWorkschedule) sessionFactory
					.openSession().get(
							"com.LAPS.dao.EmployeeWorkschedule", id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(EmployeeWorkschedule instance) {
		log.debug("finding EmployeeWorkschedule instance by example");
		try {
			List results = sessionFactory.openSession()
					.createCriteria("com.LAPS.dao.EmployeeWorkschedule")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
}
